<?php
$id = $_GET['id']; settype($id, int);
if(@$_POST['btnCancel']) btnCancel($page);
if($id == 0){ //create
	$name = 'btnSubmit';
	$display = 'Create';
	
	//hidden field user_create
	$form->getProperties(NULL, 'user_create', 2, NULL, $user, 20);
	$user_login = $form->DisplayProperties();
	//hidden field date_create
	$form->getProperties(NULL, 'date_create', 2, NULL, date('Y-m-d H:i:s'), 20);
	$date_create = $form->DisplayProperties();
	
	$type = 1; //loại sql create $type = 1;
} else {  //update
	$name = 'btnSubmit';
	$display = 'Update';
	
	$qr_detail = mysql_query("SELECT * FROM {$page} WHERE id='{$id}'");
	$detail = mysql_fetch_array($qr_detail);
	mysql_free_result($qr_detail);
	
	//hidden field user_update
	$form->getProperties(NULL, 'user_update', 2, NULL, $user, 20);
	$user_login = $form->DisplayProperties();
	
	$type = 2; //loại sql update $type = 2;
}

if(!empty($_POST)){
	$table = str_replace('_ac','',$p);
	$field = array_keys($_POST);
	$value = array_values($_POST);
	$sql->get_sql($type,$table,$field,$value,$id);
	$check = $sql->executable();
	if($check == 1) header("location:administrator.php?p=".$page);
	else echo "<p class='error'>{$check}</p>";
}

/*
********************************************************************
* $form->getProperties($displayname, $name, $type, $cssclass, $value = NULL, $length = NULL, $orther = NULL);
* $form->DisplayProperties();
* $type = 1 // text
* $type = 2 // hidden
* $type = 3 // textarea
* $type = 4 // checkbox
* $type = 41// checkbox group
* $type = 5 // radio
* $type = 6 // select
* $type = 7 // button
* $type = 8 // submit
* $type = 9 // DeQuy
********************************************************************
***********
* NOT USED
* other, lang, delete
*/
// form
echo "
<form action='' method='post' name='form1'>
<table width='620' border='0' cellspacing='0' cellpadding='5'>
";
//date create
echo $date_create;
//user login
echo $user_login;

//Trạng thái status
$value = array(1 => 'Active', 0 => 'Inactive');
if($_POST['status'] != '') $check = $_POST['status'];
else if($detail['status'] != '') $check = $detail['status'];
else $check = 1; //giá trị mặc định
$form->getProperties('Status', 'status', 5, $check, $value, ' &nbsp; ');
echo $form->DisplayProperties();
//name
if(@$_POST['name']) $value = $_POST['name']; else $value = $detail['name'];
$form->getProperties('Name', 'name', 1, 'input_medium', $value, 60);
echo $form->DisplayProperties();
//birth
if(@$_POST['birth']) $value = $_POST['birth']; else $value = $detail['birth'];
$form->getProperties('Year of birth', 'birth', 1, 'input_medium', $value, 20);
echo $form->DisplayProperties();
//company
if(@$_POST['company']) $value = $_POST['company']; else $value = $detail['company'];
$form->getProperties('Company', 'company', 1, 'input_medium', $value, 150);
echo $form->DisplayProperties();
//email
if(@$_POST['email']) $value = $_POST['email']; else $value = $detail['email'];
$form->getProperties('Email', 'email', 1, 'input_medium', $value, 50);
echo $form->DisplayProperties();
//handicap
if(@$_POST['handicap']) $value = $_POST['handicap']; else $value = $detail['handicap'];
$form->getProperties('Handicap', 'handicap', 1, 'input_medium', $value, 100);
echo $form->DisplayProperties();
//gender
$value = array(1 => 'Male', 0 => 'Female');
if($_POST['gender'] != '') $check = $_POST['gender'];
else if($detail['gender'] != '') $check = $detail['gender'];
else $check = 1; //giá trị mặc định
$form->getProperties('Gender', 'gender', 5, $check, $value, ' &nbsp; ');
echo $form->DisplayProperties();
//national
if(@$_POST['national']) $value = $_POST['national']; else $value = $detail['national'];
$form->getProperties('National', 'national', 1, 'input_medium', $value, 50);
echo $form->DisplayProperties();
//title
if(@$_POST['title']) $value = $_POST['title']; else $value = $detail['title'];
$form->getProperties('Title', 'title', 1, 'input_medium', $value, 50);
echo $form->DisplayProperties();
//phone
if(@$_POST['phone']) $value = $_POST['phone']; else $value = $detail['phone'];
$form->getProperties('Phone', 'phone', 1, 'input_medium', $value, 30);
echo $form->DisplayProperties();
//golfby
$value = array(1 =>'My-self',0 =>'VietnamWorks’s Bus');
if($_POST['golfby'] != '') $check = $_POST['golfby'];
else if($detail['golfby'] != '') $check = $detail['golfby'];
else $check = 1; //giá trị mặc định
$form->getProperties('Go to golf by', 'golfby', 5, $check, $value, ' &nbsp; ');
echo $form->DisplayProperties();
//golffee
$value = array(1 =>'Long Thanh Member',2 =>'Floating Card User',3 =>'Guest');
if($_POST['golffee'] != '') $check = $_POST['golffee'];
else if($detail['golffee'] != '') $check = $detail['golffee'];
else $check = 1; //giá trị mặc định
$form->getProperties('Golf fee', 'golffee', 5, $check, $value, ' &nbsp; ');
echo $form->DisplayProperties();

//Ngày date_update
$form->getProperties('', 'date_update', 2, 'input_medium',date('d/m/Y'),20);
echo '<div style="display:none">'.$form->DisplayProperties().'</div>';

echo $form->DisplayProperties();
//notes
if(@$_POST['notes']) $value = $_POST['notes']; else $value = $detail['notes'];
$form->getProperties('Notes', 'notes', 3, 'textarea', $value, 1, $orther);
echo $form->DisplayProperties();

echo "
<tr style='background:#b0b0b0'>
    <th align='right'>&nbsp;</th> 
    <td><input type='submit' name='{$name}' value='{$display}' id='{$name}' class='button' />
	<input type='button' name='btnCancel' value='Cancel' class='button' onClick='window.location.href=\"administrator.php?p={$page}\"'>
	</td>
</tr>
</table>
</form>
<br />
";
?>